﻿using Kanban.BLLContainer;
using Kanban.IBLL;
using Kanban.Model;
using KanbanApi.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;

namespace KanbanApi.Controllers
{
    public class UserController : BaseController
    {
        private readonly IUserService UserService = Container.Resolve<IUserService>();

        [HttpGet]
        [Route("api/User/GetData")]
        public async Task<Table<object>> GetData(string search, int pageSize, int pageIndex)
        {
            var response = await UserService.GetModelsByPageAsync(search, pageSize, pageIndex);
            return new Table<object>(response.Item1, response.Item2);
        }


        [HttpGet]
        [Route("api/User/GetModel")]
        public Task<UserId_仓码对应表> GetModel(int id)
        {
            return UserService.GetModelAsync(id);
        }

        [HttpPost]
        [Route("api/User/Save")]
        public Task<bool> Save(UserRequest request)
        {
            return UserService.Save(request.Model);
        }

        [HttpPost]
        [Route("api/User/EditPassword")]
        public Task<bool> EditPassword(UserRequest request)
        {
            var currentUser = (UserModel)RequestContext.RouteData.Values.FirstOrDefault().Value;
            return UserService.EditPassword(currentUser.Id, request.Password, request.NewPassword);
        }



        [Route("api/User/Remove")]
        public Task<bool> Remove(int id)
        {
            return UserService.DeleteAsync(id);
        }
    }
}